package edu.xidian.bdilab.jrbigdata.controller.government;

import edu.xidian.bdilab.jrbigdata.controller.response.ResponseResult;
import edu.xidian.bdilab.jrbigdata.service.government.release.ReleaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Decription GovernmentReleaseController，用于处理政府发布（包括新闻发布和政策发布）以及查看所发布的内容。
 * @Author Jin Lingming
 * @Date 2020/10/22 18:55
 * @Version 1.0
 **/
@Controller
@CrossOrigin
@Api(value="政府发布controller")
public class GovernmentReleaseController {

    @Autowired
    ReleaseService releaseService;
    @ResponseBody
    @ApiOperation("新闻发布")
    @RequestMapping(value = "/government/releaseNews", method = RequestMethod.POST)
    public ResponseResult releaseNews(@RequestParam @ApiParam(value = "政府用户名") String userName,
                                      @RequestParam @ApiParam(value = "新闻名称") String newName,
                                      @RequestParam @ApiParam(value = "新闻描述") String newDesc) throws Exception{

        ResponseResult responseResult=releaseService.releaseNews(userName,newName,newDesc);
        return responseResult;

    }

    @ResponseBody
    @ApiOperation("政策发布")
    @RequestMapping(value = "/government/releasePolicies", method = RequestMethod.POST)
    public ResponseResult releasePolicies(@RequestParam @ApiParam(value = "政府用户名") String userName,
                                      @RequestParam @ApiParam(value = "政策名称") String policyName,
                                      @RequestParam @ApiParam(value = "政策描述") String policyDesc) throws Exception{

        ResponseResult responseResult=releaseService.releasePolicies(userName,policyName,policyDesc);
        return responseResult;

    }

    @ResponseBody
    @ApiOperation("分页获取新闻（按时间排序）")
    @RequestMapping(value = "/government/getNews", method = RequestMethod.POST)
    public ResponseResult releaseNews(@RequestParam(defaultValue = "1")@ApiParam(value = "页码") int pageNum,
                                      @RequestParam(defaultValue = "10")@ApiParam(value = "每页记录数") int pageSize) throws Exception{
        ResponseResult responseResult=releaseService.getNews(pageNum,pageSize);
        return responseResult;

    }

    @ResponseBody
    @ApiOperation("分页获取政策（按时间排序）")
    @RequestMapping(value = "/government/getPolicies", method = RequestMethod.POST)
    public ResponseResult getPolicies(@RequestParam(defaultValue = "1")@ApiParam(value = "页码") int pageNum,
                                      @RequestParam(defaultValue = "10")@ApiParam(value = "每页记录数") int pageSize) throws Exception{
        ResponseResult responseResult=releaseService.getPolicies(pageNum,pageSize);
        return responseResult;

    }
}
